package com.leonwoodstudio.eventdetectionclient;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

/**
 * Created by win7 on 2017/4/3.
 */
public class LatestEventFragment extends Fragment {
    int i = 0;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_latest_event, container, false);
        return rootView;
    }

    public void UpdateEvent(String message, String image) {
        TextView text_view = (TextView)getView().findViewById(R.id.status_message);
        text_view.setText(message);
        ImageView image_view = (ImageView) getView().findViewById(R.id.received_pic);
        if (image == null) {
            image_view.setImageDrawable(null);
            return;
        }
        FileInputStream fis = null;
        try {
            fis = new FileInputStream(new File(image));
            Bitmap bm = BitmapFactory.decodeStream(fis);
            image_view.setImageBitmap(bm);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } finally {
            if (fis != null) {
                try {
                    fis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
